#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int T;
int func(int n,int m,int L,int V)
{
    int cntover = 0;
    int carv[100005] = {0};
    int card[100005] = {0};
    int cara[100005] = {0};
    int devices[100005] = {0};
    for(int i = 0;i < n;i++)
    {
        cin >> card[i] >> carv[i] >> cara[i];
    }
    for(int i = 0;i < m;i++)
    {
        cin >> devices[i];
    }
    sort(devices,devices+m);
    for(int i = 0;i < n;i++)
    {
        if(carv[i] > V && card[i] <= devices[m-1]) cntover++;
    }
    cout << cntover << " ";
    if(cntover > 0) return m-1;
    else return m;
}

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> T;
    for(int i = 0;i < T;i++)
    {
        int n,m,L,V;
        cin >> n >> m >> L >> V;
        cout << func(n,m,L,V) << endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
